<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
<!--                            <li>-->
<!--                                <label>设备类型：</label>-->
<!--                                <select name="deviceType" th:with="type=${@dict.getType('deviceType')}">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                                </select>-->
<!--                            </li>-->
                            <li>
                                <label>设备名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>设备号：</label>
                                <input type="text" name="deviceCode"/>
                            </li>
                            <li>
                                <label>物联网卡号：</label>
                                <input type="text" name="iotCardNumber"/>
                            </li>
                            <li>
                                <label>设备场地：</label>
                                <input type="text" name="position"/>
                            </li>
                            <li>
                                <label>门锁状态：</label>
                                <select name="doorLockStatus" th:with="type=${@dict.getType('doorLockStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>最新补货时间：</label>
                                <input type="text" class="time-input"   placeholder="开始时间" name="params[beginLastReplenishmentTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input"   placeholder="结束时间" name="params[endLastReplenishmentTime]"/>
                            </li>
                            <li class="select-time">
                                <label>最新上送数据时间：</label>
                                <input type="text" class="time-input"   placeholder="开始时间" name="params[beginLastUpdateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input"   placeholder="结束时间" name="params[endLastUpdateTime]"/>
                            </li>
                            <li>
                                <label>客服电话：</label>
                                <input type="text" name="customerServicePhone"/>
                            </li>
                            <li>
                                <label>最大端口数：</label>
                                <input type="text" name="maxCargoLane"/>
                            </li>
                            <li class="select-time">
                                <label>到期时间：</label>
                                <input type="text" class="time-input"   placeholder="开始时间" name="params[beginDueDtime]"/>
                                <span>-</span>
                                <input type="text" class="time-input"   placeholder="结束时间" name="params[endDueDtime]"/>
                            </li>
                            <li>
                                <label>续费状态：</label>
                                <select name="renewStatus" th:with="type=${@dict.getType('renewStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>安装状态：</label>
                                <select name="stockStatus" th:with="type=${@dict.getType('yesOrNo')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>在线状态：</label>
                                <select name="lineStatus" th:with="type=${@dict.getType('lineStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>启用状态：</label>
                                <select name="status" th:with="type=${@dict.getType('enableStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="restart()" shiro:hasPermission="biz:device:restart">
                    <i class="fa fa-history"></i> 重启
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:device:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:device:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="biz:device:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-fixed-columns-js" />
    <script th:inline="javascript">
        var adminFlag = [[${@permission.hasPermi('biz:manage:admin')}]];
        var editFlag = [[${@permission.hasPermi('biz:device:edit')}]];
        var feeFlag = [[${@permission.hasPermi('biz:device:fee')}]];
        var detailFlag = [[${@permission.hasPermi('biz:device:detail')}]];
        var portFlag = [[${@permission.hasPermi('biz:device:port')}]];
        var removeFlag = [[${@permission.hasPermi('biz:device:remove')}]];
        var deviceTypeDatas = [[${@dict.getType('deviceType')}]];
        var doorLockStatusDatas = [[${@dict.getType('doorLockStatus')}]];
        var renewStatusDatas = [[${@dict.getType('renewStatus')}]];
        var stockStatusDatas = [[${@dict.getType('yesOrNo')}]];
        var lineStatusDatas = [[${@dict.getType('lineStatus')}]];
        var statusDatas = [[${@dict.getType('enableStatus')}]];
        var prefix = ctx + "biz/device";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                startUrl: prefix + "/restart",
                fixedColumns: true,
                fixedRightNumber: 1,
                sortName: "id",
                sortOrder: "desc",
                modalName: "设备",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'tenantId',
                    title: '租户标识',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                // {
                //     field: 'merchId',
                //     title: '商户ID',
                //     visible: false,
                //     formatter: function (value, row, index) {
                //         return $.table.tooltip(value, 10, 'open');
                //     }
                // },
                // {
                //     field: 'reserve',
                //     title: '预留',
                //     visible: false,
                //     formatter: function (value, row, index) {
                //         return $.table.tooltip(value, 10, 'open');
                //     }
                // },
                // {
                //     field: 'deviceType',
                //     title: '设备类型',
                //     formatter: function(value, row, index) {
                //        return $.table.selectDictLabel(deviceTypeDatas, value);
                //     }
                // },
                {
                    field: 'name',
                    title: '设备名称',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'deviceCode',
                    title: '设备号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 20, 'open');
                    }
                },
                {
                    field: 'qrCode',
                    title: '设备二维码',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value, 500, 500);
                    }
                },
                {
                    field: 'iotCardNumber',
                    title: '物联网卡号',
                    visible: true,
                    formatter: function (value, row, index) {
                        console.log("adminFlag=",adminFlag)
                        if(adminFlag == 'hidden'){
                            return $.table.tooltip(value, 20, 'open');
                        }
                        var actions = [];
                        actions.push(value);
                        actions.push(" ");
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="renew(\'' + row.id + '\')"><i class="fa fa-battery-3"></i> 续费</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'firmwareVersion',
                    title: '固件版本',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'lastOrderNo',
                    title: '最近一次订单号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'lat',
                    title: '维度',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'lon',
                    title: '经度',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'position',
                    title: '设备场地',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'signalIntensity',
                    title: '信号强度0-100',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'discount',
                    title: '折扣',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'doorLockStatus',
                    title: '门锁状态',
                    visible: false,
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(doorLockStatusDatas, value);
                    }
                },
                {
                    field: 'lastReplenishmentTime',
                    title: '最新补货时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 20, 'open');
                    }
                },
                {
                    field: 'lastUpdateTime',
                    title: '最新上送数据时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 20, 'open');
                    }
                },
                {
                    field: 'customerServicePhone',
                    title: '客服电话',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'maxCargoLane',
                    title: '最大端口数',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'dueDtime',
                    title: '到期时间',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'renewStatus',
                    title: '续费状态',
                    visible: false,
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(renewStatusDatas, value);
                    }
                },
                {
                    field: 'stockStatus',
                    title: '安装状态',
                    visible: false,
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(stockStatusDatas, value);
                    }
                },
                {
                    field: 'lineStatus',
                    title: '在线状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(lineStatusDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '启用状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },

                {
                    field: 'createTime',
                    title: '安装时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a style="margin-top: 3px;" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-primary btn-xs ' + portFlag + '" href="javascript:void(0)" onclick="cargo(\'' + row.id + '\')"><i class="fa fa-navicon"></i> 端口管理</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-primary btn-xs ' + feeFlag + '" href="javascript:void(0)" onclick="puton(\'' + row.deviceCode + '\')"><i class="fa fa-cubes"></i> 收费方案</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-info"></i> 详情</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 重启
         */
        function restart() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要启动选中的" + rows.length + "台设备吗?", function() {
                var url = table.options.startUrl;
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }
        /**
         * 续费
         **/
        function renew(id) {
            var url = ctx + '/biz/renew?deviceId=' + id + '&time=' + (new Date()).getTime();
            $.modal.openTab("续费记录", url);
        }
        function detail(id) {
            var url = prefix + '/detail/' + id + "?time=" + (new Date()).getTime();
            $.modal.openTab("设备详情", url);
        }

        /**
         * 端口管理
         * @param id
         */
        function cargo(id) {
            var url = ctx + 'biz/cargo?deviceId=' + id + "&time=" + (new Date()).getTime();
            $.modal.openTab("设备端口", url);
        }
        /**
         * 收费方案
         * @param id
         */
        function puton(deviceCode) {
            var url = ctx + '/biz/goods?deviceSn=' + deviceCode + "&time=" + (new Date()).getTime();
            $.modal.openTab("收费方案", url);
        }
        /**
         * 设备补货
         * @param id
         */
        function replenishment(id) {
            var url = ctx + '/biz/cargo/replenishment?deviceId=' + id + "&time=" + (new Date()).getTime();
            $.modal.openTab("设备补货", url);
        }
    </script>
</body>
</html>